<!--
 * @Author: your name
 * @Date: 2022-01-03 19:54:51
 * @LastEditTime: 2022-01-18 19:42:26
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \vue\vue-douban-pc\src\views\adminUser.vue
-->
<template>
    <div class="adminuser">
        <el-col :span="4">
            <h1></h1>
        </el-col>
        <el-col :span="20">
            <el-table :data="user" style="width: 100%;" max-height="658">
                <el-table-column label="序列" type="index"></el-table-column>
                <el-table-column label="用户名" prop="username" width="150"></el-table-column>
                <el-table-column label="电话" prop="phone" width="150"></el-table-column>
                <el-table-column label="邮箱" prop="email" width="150"></el-table-column>
                <el-table-column label="管理员" prop="admin" width="150"></el-table-column>
                <el-table-column align="right">
                    <template slot-scope="scope">
                        <el-button size="mini" type="success" @click="setAdmin(scope.row)">设置管理员</el-button>
                        <el-button
                            size="mini"
                            type="primary"
                            @click="deleteAdmin(scope.row)"
                        >移除管理员</el-button>
                        <el-button
                            size="mini"
                            type="danger"
                            @click="handleDelete(scope.$index, scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-col>
    </div>
</template>

<script>
export default {
    name: 'VueAdminuser',

    data() {
        return {
            user: [],
        };
    },

    mounted() {

    },
    created() {
        this.getUser();
    },
    methods: {
        getUser() {
            this.axios.get("/getUser").then((res) => {
                this.user = res.data
                console.log(res.data);
            })
        },
        setAdmin(row) {
            this.axios.post("/setAdmin", {
                userId: row.user_id
            }).then((res) => {
                let {state} = res.data.data
                if(state == "success"){
                    this.$message.success('设置成功')
                    this.$router.go(0)
                }else if(state == "fail"){
                    this.$message.error('设置失败')
                }
            })
        },
        deleteAdmin(row){
            this.axios.post("/deleteAdmin",{
                userId: row.user_id
            }).then(( res=>{
                let {state} = res.data.data
                if(state == "success"){
                    this.$message.success('移除成功')
                    this.$router.go(0)
                }else if(state == "fail"){
                    this.$message.error('移除失败')
                } 
            }))
        }
    },
};
</script>

<style lang="scss" scoped>
.adminuser {
    position: relative;
    z-index: 10;
}
</style>